/** \file buf_buffer.h Multipurpose byte strBuffer structure and methods.
*/



#ifndef BUFFER_H
#define BUFFER_H
#include "loc_types.h"

// structure/typdefs

/** BUF_tstrBuffer structure
*/
typedef struct struct_tstrBuffer
{
	u8 *pu8DataPointer;		///< the physical memory address where the strBuffer is stored
	u16 u16Size;			///< the allocated size of the strBuffer
	u16 u16DataLength;		///< the length of the data currently in the strBuffer
	u16 u16DataIndex;		///< the index into the strBuffer where the data starts
} BUF_tstrBuffer;

// function prototypes

/** Initialize a strBuffer to start at a given address and have given size.
*/
 extern void	BUF_vidInit(BUF_tstrBuffer* strBuffer, u8 *start, u16 size);

/** Get the first byte from the front of the strBuffer.
*/
extern u8	BUF_u8GetFromFront(BUF_tstrBuffer* strBuffer);

/** dump (discard) the first numbytes from the front of the strBuffer.
*/
 extern void BUF_vidDumpFromFront(BUF_tstrBuffer* strBuffer, u16 u16Numbytes);

/** Get a byte at the specified index in the strBuffer (kind of like array access).
* note: this does not remove the byte that was read from the strBuffer
*/
 extern u8	BUF_u8GetAtIndex(BUF_tstrBuffer* strBuffer, u16 u16Index);

/** Add a byte to the end of the strBuffer.
*/
 extern u8	BUF_u8AddToEnd(BUF_tstrBuffer* strBuffer, u8 u8Data);

/** Check if the strBuffer is full/not full (returns non-zero value if not full).
*/
 extern u8	BUF_u8IsNotFull(BUF_tstrBuffer* strBuffer);

/** Flush (clear) the contents of the strBuffer.
*/
 extern void	BUF_vidFlush(BUF_tstrBuffer* strBuffer);


/** Searches for a string in the indicated buffer.
*/
extern u8 BUF_u8SearchString(BUF_tstrBuffer* strBuffer,u8 u8StartIndex, const u8 *pu8Str,u8 u8StringLength);

/** Returns the length of the data in the buffer.
*/
extern u16 BUF_u16GetDataLength(BUF_tstrBuffer* strBuffer);
#endif

